<?php

/**
 * ContactForm class.
 * ContactForm is the data structure for keeping
 * contact form data. It is used by the 'contact' action of 'SiteController'.
 */
class UserSettingsForm extends CFormModel
{
	public $old_password;
	public $new_password;
	public $new_password2;
	public $profile;
	//public $verifyCode;

	/**
	 * Declares the validation rules.
	 */
	public function rules()
	{
		return array(
			// name, email, subject and body are required
			array('old_password, new_password, new_password2', 'required'),
			array('old_password', 'checkOldPassword'),
			// email has to be a valid email address
			//array('email', 'email'),
			// verifyCode needs to be entered correctly
			//array('verifyCode', 'captcha', 'allowEmpty'=>!CCaptcha::checkRequirements()),
			
			array('new_password', 'compare', 'compareAttribute'=>'new_password2'),
		);
	}
	
	public function checkOldPassword($attribute,$params)
    {
        $user=User::model()->findByPk(Yii::app()->user->id);
        if(!$user->validatePassword($this->old_password))
            $this->addError('old_password','Incorrect old password.');
    }

	/**
	 * Declares customized attribute labels.
	 * If not declared here, an attribute would have a label that is
	 * the same as its name with the first letter in upper case.
	 */
	/*public function attributeLabels()
	{
		return array(
			'verifyCode'=>'Verification Code',
		);
	}*/
}